import { extend } from "vee-validate";
import { required } from "vee-validate/dist/rules";

export const phoneReg =
  /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/;

export const passwordReg = /^[0-9A-Za-z_]{6,18}$/;

// 定义表单校验规则
extend("phoneRequired", {
  ...required,
  message: "请输入手机号",
});

extend("phone", {
  validate(val) {
    // val校验表单的表单数据
    // 返回true表单校验通过，返回false表单校验失败
    return phoneReg.test(val);
  },
  message: "手机号不符合规范",
});

extend("passwordRequired", {
  ...required,
  message: "请输入密码",
});

extend("password", {
  validate(val) {
    return passwordReg.test(val);
  },
  message: "密码不符合规范",
});
